import * as Store from "@/store";
import { useRoute, useRouter } from "vue-router";

const usePage = (provideState: { getToolBarItem: Function }) => {
  const prData = Store.useProcessData();
  // 返回
  const route = useRoute();
  const router = useRouter();
  const handlePageBack = () => {
    if( route.query.backPath === '1' ){
      window.location.href = `${location.origin}/#!/taskdetail/${route.query.taskId}/editor`;
    } else {
      router.back();
    }
  };
  // 上一个
  const handlePrevClick = () => {
    prData.getDecreaseCurrent();
    prData.refreshInterface(route);
    // router.go(0);
  };
  // 下一个
  const handleNextClick = () => {
    prData.getIncreaseCurrent();
    prData.refreshInterface(route);
    // router.go(0);
  };
  // 提交
  const handleSubmit = () => {
    provideState.getToolBarItem(() => {
      return {
        type: 'save'
      }
    });
  };
  
  return {
    handlePageBack,
    handlePrevClick,
    handleNextClick,
    handleSubmit
  }
}
export default usePage;